﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using PMisuseAn.io;

namespace PMisuseAn
{
    /// <summary>
    /// Interaction logic for NewGroupFunctionWindow.xaml
    /// </summary>
    public partial class NewGroupFunctionWindow : Window
    {
        public NewGroupFunctionWindow()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string functionName = function_name.Text;
            functionName = functionName.Trim();
            if (functionName.Count() == 0)
            {
                MessageBoxResult result = MessageBox.Show("Empty name box!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            List<string> groupFunctions = MisUseAnObjectsDB.loadAllGroupFunctions(MainWindow.clusterName);
            foreach (string gf in groupFunctions)
            {
                if (gf.Equals(functionName))
                {
                    MessageBoxResult result = MessageBox.Show("Function name already exist", "Conflict", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }
            MisUseAnObjectsDB.addGroupFunctionDB(functionName, MainWindow.clusterName);

            this.Close();
        }
    }
}
